﻿using UnityEngine;
using System.Collections;

public class Block : MonoBehaviour {

    /// <summary>
    /// 左下角方块的位置，用于作为方块位置的基准
    /// </summary>
    private float xOff = -2.1f;
    private float yOff = -3.6f;

    /// <summary>
    /// 相邻行和列间方块位置的偏移
    /// </summary>
    private float xDelta = 1.4f;
    private float yDelta = 2.6f;

    /// <summary>
    /// 方块所对应的分数
    /// </summary>
    public int score = 0;

    /// <summary>
    /// 行列索引
    /// </summary>
    public int colIndex = 0;
    public int rowIndex = 0;

    void OnMouseDown()
    {
        GameController.Instance.PlaySound();
        GameController.Instance.AddScore(score);
        GameController.Instance.RemoveBlock(this);
    }

    public void SetPosition(int colIndex, int rowIndex)
    {
        this.colIndex = colIndex;
        this.rowIndex = rowIndex;
        transform.position = new Vector3(xOff + colIndex * xDelta, yOff + rowIndex * yDelta, 0);
    }

    /// <summary>
    /// 向下移动一行
    /// </summary>
    public void MoveDown()
    {
        this.SetPosition(this.colIndex, this.rowIndex - 1);
    }

    /// <summary>
    /// 销毁自身
    /// </summary>
    public void Destroy()
    {
        GameObject.Destroy(transform.gameObject);
    }
}
